package org.doubango.jni;

import org.opencv.core.Mat;

public class Libyuv {

    static {
        System.loadLibrary("yuv");
    }

    public native static void YV12ToI420(byte[] yv12Bytes, byte[] i420Bytes, int width, int height);

    public static void YV12ToNV12(byte[] yv12Bytes, byte[] nv12Bytes, int width, int height) {
        I420ToNV21(yv12Bytes, nv12Bytes, width, height);
    }

    public static native void NV21ToI420(byte[] nv21Bytes, byte[] i420Bytes, int width, int height);

    public static native void I420Rotate(byte[] srcI420Bytes, byte[] destI420Bytes, int width, int height, int degree);

    public static native void I420ToNV12(byte[] i420Bytes, byte[] nv12Bytes, int width, int height);

    /** I420转NV21，也可用于YV12转NV12，因为YV12中的UV和I420中的UV顺序正好相反，而NV12中的UV和NV21中的UV也正好相反，所以转换的操作是一样的 */
    public static native void I420ToNV21(byte[] i420Bytes, byte[] nv21Bytes, int width, int height);

    public static native void YV12ToNV12Rotate180(byte[] yv12Bytes, byte[] nv12Bytes, int width, int height);
    public static native void YV12ToNV12Rotate270Or90(byte[] yv12Bytes, byte[] nv12Bytes, int width, int height, boolean is270);

    public static native void NV21ToNV12(byte[] nv21Bytes, byte[] nv12Bytes, int width, int height);
    public static native void NV21ToRGB(byte[] nv21Bytes, byte[] rgbBytes, int width, int height);
    public static native void fillBytesToMat(byte[] bytes, Mat mat);

    /** NV21转NV12，比上面的NV21ToNV12效率要高一点，此方法实现是直接修改原数组，而上面的NV21ToNV12方法是把转换后的数据放到新数组中 */
    public static native void NV21ToNV12Inplace(byte[] nv21Bytes, byte[] uv12Bytes, int width, int height);

    /**
     * 声音增强
     * @param audioBytes pcm音频数据
     * @param factor 放大倍数，原始大小为1，比1大，则为声音放大。
     * @param f 传一个长度为1的空数组即可，此参数要保存为成员变量，每次都传同一个成员变量。
     */
    public static native void audioEnhance(byte[] audioBytes, double factor, double[] f);

    public static native void pcmFileToWavFile(String pcmFilePath, int channelCount, int simpleRate, String wavFilePath);

    /**
     * 把ARGB格式的图片与NV12格式的图片混合到一起，要求两张图片的宽高一样
     * @param argbBytes RGBA数据
     * @param nv12Bytes NV12数据
     * @param width 图片宽
     * @param height 图片高
     */
    public static native void blendARGBToNV12(byte[] argbBytes, byte[] nv12Bytes, byte[] destNV12Bytes, byte[] argbForNV12, byte[] argbDest,  int width, int height);

    public static native void RGBAToARGB(byte[] rgbaBytes, int arrayOffset, byte[] argbBytes, int width, int height);

}
